package com.tuling.jvm;

import sun.misc.Launcher;

import java.net.URL;

/**
 * 类加载器
 */
public class TestJDKClassLoader {
    public static void main(String[] args) {
        System.out.println(String.class.getClassLoader()); //c++生成对象 不是java生成对象 结果为null 引导类加载器
        System.out.println(com.sun.crypto.provider.DESKeyFactory.class.getClassLoader()); //扩展类加载器
        System.out.println(TestJDKClassLoader.class.getClassLoader()); //应用程序类加载器
        System.out.println();

        ClassLoader appClassLoader = ClassLoader.getSystemClassLoader();
        ClassLoader extClassloader = appClassLoader.getParent();
        ClassLoader bootstrapLoader = extClassloader.getParent();
        System.out.println("the boorstrapLoader:"+ bootstrapLoader);
        System.out.println("the extClassloader:"+ extClassloader);
        System.out.println("the appClassLoader" + appClassLoader);

        System.out.println();
        System.out.println("bootstrapLoader加载以下文件:");
        URL[] urLs = Launcher.getBootstrapClassPath().getURLs();
        for (int i = 0; i <urLs.length ; i++) {
            System.out.println(urLs[i]);
        }

        System.out.println();
        System.out.println("extClassLoader加载以下文件:");
        System.out.println(System.getProperty("java.ext.dirs"));

        System.out.println();
        System.out.println("appClassLoader加载以下文件:");
        System.out.println(System.getProperty("java.class.path"));
    }
}
